package logic

import (
	"context"
	"zhihu/zhihurpc/models/mysql"
	"zhihu/zhihurpc/zhihurpcclient"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemanswerslistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProblemanswerslistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemanswerslistLogic {
	return &ProblemanswerslistLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProblemanswerslistLogic) Problemanswerslist(in *zhihurpc.ProblemanswerslistRequest) (*zhihurpc.ProblemanswerslistResponse, error) {
	// todo: add your logic here and delete this line
	var list []mysql.Ansewer
	mysql.DB.Debug().Find(&list)
	var lists []*zhihurpcclient.Problemanswerslist
	for _, problemanswers := range list {
		answerslist := zhihurpcclient.Problemanswerslist{
			Id:        int64(problemanswers.ID),
			UserId:    int64(problemanswers.UserId),
			ProblemId: int64(problemanswers.ProblemId),
			Content:   problemanswers.Content,
		}
		lists = append(lists, &answerslist)
	}
	return &zhihurpc.ProblemanswerslistResponse{
		List: lists,
	}, nil
}
